package xyz.xtt.asset.enums;

import java.util.Arrays;
import java.util.Objects;

import com.google.common.primitives.Ints;

import xyz.xtt.asset.api.enums.AssetTypeEnum;

/**
 * 地皮类型
 * 
 * 上游业务 0是未知 1是普通 2是商业 3是地标
 * 
 * @author huqibo
 *
 */
public enum GroundTypeEnum {
	/**
	 * 普通地皮
	 */
	NORMAL(AssetTypeEnum.GROUND, 0, "普通"),
	/**
	 * 商业地皮
	 */
	COMMERCIAL(AssetTypeEnum.GROUND, 1, "商业"),
	/**
	 * 地标地皮
	 */
	LANDMARK(AssetTypeEnum.GROUND, 2, "地标"),;

	/**
	 * 一级分类
	 */
	private AssetTypeEnum assetTypeEnum;
	/**
	 * 编码
	 */
	private int code;
	/**
	 * 描述
	 */
	private String desc;

	private GroundTypeEnum(AssetTypeEnum assetTypeEnum, int code, String desc) {
		this.assetTypeEnum = assetTypeEnum;
		this.code = code;
		this.desc = desc;
	}

	public int code() {
		return code;
	}

	public String desc() {
		return desc;
	}

	public AssetTypeEnum assetType() {
		return assetTypeEnum;
	}

	public static GroundTypeEnum convert(String checkType) {
		return Arrays.asList(GroundTypeEnum.values()).stream().filter(x -> Objects.equals(x.name(), checkType))
				.findFirst().orElse(null);
	}

	public static GroundTypeEnum queryConvert(String checkType) {
		return Arrays.asList(GroundTypeEnum.values()).stream()
				.filter(x -> Objects.equals(x.code(), Ints.tryParse(checkType))).findFirst().orElse(null);
	}
}
